package com.situ.water_read.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.situ.water_read.pojo.RdTask;
import com.situ.water_read.service.RdTaskService;
import com.situ.water_system.pojo.SyEmp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Angel
 * @since 2020-12-01
 */
@RestController
@RequestMapping("/rd-task")
public class RdTaskController {
    @Autowired
    RdTaskService service;
    @GetMapping("querytask")
    public List<Map> querytask(){
        List<Map> map=service.querytask();
        return map;
    }
    @GetMapping("/queryEmp")
    public List<SyEmp> queryEmp(){
        List<SyEmp> list=service.queryEmpbylwt();
        return list;
    }
    @PostMapping("/addtask")
    public void addtask(RdTask task){
        System.out.println(task.toString());
        System.out.println(task.getVolumeId());
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("ReadYear",task.getReadYear());
        wrapper.eq("ReadMonth",task.getReadMonth());
        wrapper.eq("VolumeId",task.getVolumeId());
        RdTask rdTask=service.queryTaskId(wrapper);
        if(rdTask!=null){//修改
            task.setId(rdTask.getId());
            service.updatetask(task);
        }else{
            //向分配表添加新数据
        service.addtask(task);
        }
        //修改抄表数据中的抄表人，根据表册id
        service.updateread(task);

    }
}

